package memo.model;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class DriverLoadingListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent event) {  
		try {     
			ServletContext context = event.getServletContext(); // 서블릿 컨텍스트 가져오기
			String url = context.getInitParameter("URL");   // web.xml에서 컨텍스트파라미터 (DB property) 가져오기 
			String userName = context.getInitParameter("UserName");  
			String password = context.getInitParameter("Password");  

			MemoDAO.getInstance().init(url,userName,password);             //DB 연결하는 MemberDAO의 init 메소드 호출

		} catch (Exception e) {  
			e.printStackTrace();
		}    
	}  
	@Override
	public void contextDestroyed(ServletContextEvent event) {    //DB 해제하는 MemberDAO의 finish 메소드 호출
		try {  

			MemoDAO.getInstance().finish();

		} catch (Exception e) {  
			e.printStackTrace();  
		}    
	}  

}
